<?php
include_once '../Utility/simplehtmldom/simple_html_dom.php';
/**
 * 
 * @author Laura Magrini
 *
 */
class MuchParametersException extends Exception {
	
	function __construct($message, $code=null) {
		if ($code==null)
			parent::__construct($message,null);
		else
			parent::__construct($message,$code);
	}
	
	function toXML($mode) {
		$partenza=null;
		$arrivo=null;

		$html=$this->getMessage();
		$html = str_get_html($html);	
		$text = $html->plaintext;
		
		If(strpos($text, "indirizzo di partenza (molti trovati)")==true)
			$partenza="Correggere l'indirizzo di partenza";
		If(strpos($text, "indirizzo di arrivo (molti trovati)")==true)
			$arrivo="Correggere l'indirizzo di arrivo";
	
				
		$xml="";
		$xml=$xml."<EXCEPTION>\n";
		if($partenza!=NULL){
			$type=$html->find('select[name=startaddress]');
			$xml=$xml."<TYPE>$partenza</TYPE>\n";
			$ret0 = $type[0]->find('option[value=]');
			if($ret0!=NULL){
				$xml=$xml."<LISTOPTION>\n";
				for($i=0; $i<count($ret0); $i++){
					$str = $ret0[$i]->plaintext;
					$parts = explode(">",$str);	
					$xml=$xml."<OPTION>".$parts[0]."</OPTION>\n";
				}
				$xml=$xml."</LISTOPTION>\n";
			}
		}
		if($arrivo!=NULL){
			$type=$html->find('select[name=stopaddress]');
			$xml=$xml."<TYPE>$arrivo</TYPE>\n";
			$ret0 = $type[0]->find('option[value=]');
			if($ret0!=NULL){
				$xml=$xml."<LISTOPTION>\n";
				for($i=0; $i<count($ret0); $i++){
					$str = $ret0[$i]->plaintext;
					$parts = explode(">",$str);	
					$xml=$xml."<OPTION>".$parts[0]."</OPTION>\n";
				}
				$xml=$xml."</LISTOPTION>\n";
			}
		}
		$xml=$xml."</EXCEPTION>\n";
		return $xml;
	}
	
	function getElementStartTag() {
		return "<EXCEPTION>";
		
	}
	
	function getElementEndTag() {
		return "</EXCEPTION>";
		
	}
	
	
	
	
}